package com.ruoyi.web.controller.sj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sj.domain.Follow;
import com.ruoyi.sj.service.IFollowService;
import com.ruoyi.web.core.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;

/**
 * 关注 信息操作处理
 * 
 * @author tyc@yanyu.com
 * @date 2018-11-28
 */
@Controller
@RequestMapping("/sj/follow")
public class FollowController extends BaseController
{
    private String prefix = "sj/follow";
	
	@Autowired
	private IFollowService followService;
	
	@RequiresPermissions("sj:follow:view")
	@GetMapping()
	public String follow()
	{
	    return prefix + "/follow";
	}
	
	/**
	 * 查询关注列表
	 */
	@RequiresPermissions("sj:follow:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Follow follow)
	{
		startPage();
        List<Follow> list = followService.selectFollowList(follow);
		return getDataTable(list);
	}
	
	/**
	 * 新增关注
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存关注
	 */
	@RequiresPermissions("sj:follow:add")
	@Log(title = "关注", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Follow follow)
	{		
		return toAjax(followService.insertFollow(follow));
	}

	/**
	 * 修改关注
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Follow follow = followService.selectFollowById(id);
		mmap.put("follow", follow);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存关注
	 */
	@RequiresPermissions("sj:follow:edit")
	@Log(title = "关注", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Follow follow)
	{		
		return toAjax(followService.updateFollow(follow));
	}
	
	/**
	 * 删除关注
	 */
	@RequiresPermissions("sj:follow:remove")
	@Log(title = "关注", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(followService.deleteFollowByIds(ids));
	}
	
}
